/*******************************************************************************

                  LVGL 输入法之输入法类型选择软键盘实现
本模块含剪切板行，具体由上层实现
字符含中文，故本文件应保存为UTF8格式
*******************************************************************************/
#include "lvIME_Base.h"
#include <string.h>

//------------------------------nx3模式键盘布局定义------------------------------
#ifdef SUPPORT_LV_IME_T9
  #define _PKEY  "中 T9"
#elif defined(SUPPORT_LV_IME_GUIDE)
  #define _PKEY  "中 Guide"
#else //其它时，可定制用户当前键盘
  #define _PKEY  "ANSI"
#endif
static const char * BTNMAP_CONST _KbBtnMap[] = {
  LV_SYMBOL_LEFT, LV_SYMBOL_EDIT, LV_SYMBOL_CUT, LV_SYMBOL_COPY, LV_SYMBOL_PASTE, LV_SYMBOL_RIGHT, LV_SYMBOL_BACKSPACE, "\n",
  _PKEY,   "内码 Code",  "123", "\n",
  "ABC",   "abc",      "符 Sign", "\n",
  "拼音9", "拼音26",    "符 Custom", ""};
//位置转键值,与_KbBtnMapV对应
static const signed char _KbPos2Key[] = {
  LV_KEY_LEFT, LV_KEY_UP, LV_KEY_DOWN, LV_KEY_ENTER, LV_KEY_ESC, LV_KEY_RIGHT, LV_KEY_BACKSPACE,
  '0', '1', '2',  '3', '4', '5',  '6', '7', '8',};

//---------------------------------创建类型选择软键盘-----------------------------
lv_obj_t *lvIME_CreateTypeSel(lv_event_cb_t _cbEventHandler, //回调函数
                              void *pv,//回调函数带的参数
                              unsigned short DisMask)//禁止使用按键掩码
{
  lv_obj_t * pBtnM = lvIME_CreateKeyStart(_cbEventHandler, pv);
  lv_obj_set_size(pBtnM, lv_pct(100), LV_IME_KB_ROW_HIGHT * 4);
  lv_buttonmatrix_set_map(pBtnM, (const char **)_KbBtnMap);

  //禁止部分按键的使用
  if(DisMask){
    for(unsigned char Pos = 0; Pos < 9; Pos++){
      if(DisMask & (unsigned short)1 << Pos) //禁用了
        lv_buttonmatrix_set_button_ctrl(pBtnM, Pos + 7, LV_BUTTONMATRIX_CTRL_DISABLED);
    }
  }

  lv_obj_update_layout(pBtnM); //强制更新布局以使大小生效
  return pBtnM;
}

//-----------------------------类型选择按键后的键值---------------------
//返回值为ASC数字
unsigned char lvIME_GetKeyTypeSel(lv_obj_t *pBtnM) //lv_buttonmatrix对像
{
  unsigned char KeyId = lv_btnmatrix_get_selected_btn(pBtnM);
  return _KbPos2Key[KeyId];
}
